This document presents an analysis of the number of people migrating from one country (left) to another (right). The interactive Sankey diagram below visualizes these migration flows, offering insights into the patterns and volume of migration between different countries.
Overview
Show the code
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Show the code
library(viridis)
Loading required package: viridisLite
Show the code
library(patchwork)library(hrbrthemes)
NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
Show the code
library(circlize)
========================================
circlize version 0.4.15
CRAN page: https://cran.r-project.org/package=circlize
Github page: https://github.com/jokergoo/circlize
Documentation: https://jokergoo.github.io/circlize_book/book/
If you use it in published research, please cite:
Gu, Z. circlize implements and enhances circular visualization
in R. Bioinformatics 2014.
This message can be suppressed by:
suppressPackageStartupMessages(library(circlize))
========================================
Show the code
library(networkD3)# Load and prepare the datadata <-read.table("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/13_AdjacencyDirectedWeighted.csv", header=TRUE)data_long <- data %>%rownames_to_column() %>%gather(key ='key', value ='value', -rowname) %>%filter(value >0)colnames(data_long) <-c("source", "target", "value")data_long$target <-paste(data_long$target, " ", sep="")# Create nodesnodes <-data.frame(name=c(as.character(data_long$source), as.character(data_long$target)) %>%unique())# Create source and target IDsdata_long$IDsource <-match(data_long$source, nodes$name) -1data_long$IDtarget <-match(data_long$target, nodes$name) -1# Define color scaleColourScal <-'d3.scaleOrdinal().range(["#FDE725FF","#B4DE2CFF","#6DCD59FF","#35B779FF","#1F9E89FF","#26828EFF","#31688EFF","#3E4A89FF","#482878FF","#440154FF"])'# Create the Sankey diagramsankeyNetwork(Links = data_long, Nodes = nodes,Source ="IDsource", Target ="IDtarget",Value ="value", NodeID ="name", sinksRight=FALSE, colourScale=ColourScal, nodeWidth=40, fontSize=13, nodePadding=20)
Key Insights
Migration Patterns: Observe which countries are the most common sources and destinations for migrants.
Volume of Migration: Identify the countries with the highest number of migrants.
Regional Trends: Analyze the regional trends and how migration flows vary between different parts of the world.
Detailed Analysis
To dive deeper into the data, we use various visualization techniques and data summarizations:
The migration data reveals significant trends and patterns in global migration. By leveraging data visualization tools, we can uncover valuable insights that help understand the movement of people across countries.
Feel free to explore the interactive elements and delve deeper into the analysis.